package com.cyan.teamquestionnaire.service.Impl;

import com.cyan.teamquestionnaire.entity.SecurityQuestion;
import com.cyan.teamquestionnaire.mappers.SecurityQuestionMapper;
import com.cyan.teamquestionnaire.service.SecurityQuestionService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

@Service
public class SecurityQuestionServiceImpl implements SecurityQuestionService {

    @Resource
    SecurityQuestionMapper securityQuestionMapper;

    @Override
    public SecurityQuestion getQuestionByName(String name) {
        return securityQuestionMapper.getQuestionByName(name);
    }

    @Override
    public int createSecurityQuestion(SecurityQuestion securityQuestion) {
        // 密保问题已存在，不能新增
        if(getQuestionByName(securityQuestion.getUserName()) != null) return 0;
        securityQuestionMapper.createSecurityQuestion(securityQuestion);
        return 1;
    }

    @Override
    public void modifySecurityQuestion(SecurityQuestion securityQuestion) {
        securityQuestionMapper.modifySecurityQuestion(securityQuestion);
    }

    @Override
    public void deleteSecurityQuestion(String name) {
        securityQuestionMapper.deleteSecurityQuestion(name);
    }
}
